package com.sxj.corejava.code09_集合.Collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author 石小俊
 * 2024年07月25日 14:41
 */
public class Test01_集合工具类 {

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        System.out.println(list);

        Collections.addAll(list,8,7,6,5,4,3);
        System.out.println(list);
        System.out.println(Collections.max(list));
        System.out.println(Collections.min(list));

        Collections.sort(list);
        System.out.println(list);
        List<String> list2 = new ArrayList<>();
        Collections.addAll(list2,"jack","admin","tom","lucy","alex");
        Collections.sort(list2);
        System.out.println(list2);
        System.out.println(Collections.max(list2));
        System.out.println(Collections.min(list2));

        Collections.sort(list2, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                if(o1.length() > o2.length()){
                    return 1;
                } else if(o1.length() < o2.length()){
                    return -1;
                }
                return 0;
            }
        });
        System.out.println(list2);
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                if(o1 > o2){
                    return -1;
                } else if(o1 < o2){
                    return 1;
                }
                return 0;
            }
        });
        System.out.println(list);

        Collections.reverse(list);
        Collections.addAll(list,1,2,3,2,3);
        System.out.println(list);

        Collections.replaceAll(list,2,12);
        System.out.println(list);

        Collections.swap(list,2,5);
        System.out.println(list);

        Collections.fill(list,10);
        System.out.println(list);
    }

}
